home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / Adobe AIR / Versions / 1.0 / Adobe AIR Application Installer.swf / scripts / components / ExtendedImage.as next >
Text File  |  2008-10-29  |  2KB  |  90 lines

  1. package components
  2. {
  3.    import flash.events.SecurityErrorEvent;
  4.    import flash.filesystem.File;
  5.    import flash.filesystem.FileMode;
  6.    import flash.filesystem.FileStream;
  7.    import flash.utils.ByteArray;
  8.    import mx.controls.Image;
  9.    import mx.events.PropertyChangeEvent;
  10.    
  11.    public class ExtendedImage extends Image
  12.    {
  13.        
  14.       
  15.       private var _sourceFilePath:String;
  16.       
  17.       public function ExtendedImage()
  18.       {
  19.          super();
  20.          this.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onSecurityError);
  21.       }
  22.       
  23.       override protected function commitProperties() : void
  24.       {
  25.          var fs:FileStream = null;
  26.          var f:File = null;
  27.          var bytes:ByteArray = null;
  28.          if(this._sourceFilePath)
  29.          {
  30.             try
  31.             {
  32.                f = new File(this._sourceFilePath);
  33.                fs = new FileStream();
  34.                fs.open(f,FileMode.READ);
  35.                bytes = new ByteArray();
  36.                fs.readBytes(bytes,0,fs.bytesAvailable);
  37.                source = bytes;
  38.             }
  39.             catch(e:Error)
  40.             {
  41.                source = getStyle("brokenImageSkin");
  42.             }
  43.             finally
  44.             {
  45.                if(fs)
  46.                {
  47.                   fs.close();
  48.                }
  49.             }
  50.          }
  51.          super.commitProperties();
  52.       }
  53.       
  54.       [Bindable(event="propertyChange")]
  55.       public function set sourceFilePath(param1:String) : void
  56.       {
  57.          var _loc2_:Object = this.sourceFilePath;
  58.          if(_loc2_ !== param1)
  59.          {
  60.             this._2099171076sourceFilePath = param1;
  61.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"sourceFilePath",_loc2_,param1));
  62.          }
  63.       }
  64.       
  65.       private function onSecurityError(param1:SecurityErrorEvent) : void
  66.       {
  67.          trace("SecurityError: " + param1.errorID + " : ");
  68.       }
  69.       
  70.       private function set _2099171076sourceFilePath(param1:String) : void
  71.       {
  72.          if(param1 == null && this._sourceFilePath)
  73.          {
  74.             source = null;
  75.             this._sourceFilePath = null;
  76.          }
  77.          else
  78.          {
  79.             this._sourceFilePath = param1;
  80.          }
  81.          invalidateProperties();
  82.       }
  83.       
  84.       public function get sourceFilePath() : String
  85.       {
  86.          return this._sourceFilePath;
  87.       }
  88.    }
  89. }
  90.